package com.hsd.netty.client.strategy;

import com.hsd.netty.client.enums.MessageType;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author s.he
 * on 2020/6/6
 */
@Service
public class NettyMessageExecutor {

    private static Map<MessageType, NettyMessageAdapter> NETTY_MAP = new HashMap<>(4);

    static {
        NETTY_MAP.put(MessageType.LOGIN, new LoginStrategy());
        NETTY_MAP.put(MessageType.HEART_BEAT, new HeartBeatStrategy());
        NETTY_MAP.put(MessageType.RESPONSE, new ResponseStrategy());

    }

    public void execute(MessageType type, ChannelHandlerContext ctx, Object msg) {
        NETTY_MAP.get(type).handleServerResponse(ctx, msg);
    }
}
